#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int distanceBetweenBusStops(vector<int>& distance, int start, int destination) {
        int n = distance.size();

        int clock = start, c_clock = start - 1;
        if (clock >= n) clock %= n;
        if (c_clock < 0) c_clock += n;

        long long clock_count = 0, c_clock_count = 0;
        int c_destination = destination - 1 < 0 ? destination - 1 + n : destination - 1;

        while (clock != destination || c_clock != c_destination)
        {

            clock_count += (clock == destination ? 0 : distance[clock++]);
            if (clock >= n) clock %= n;

            c_clock_count += (c_clock == destination - 1 ? 0 : distance[c_clock--]);
            if (c_clock < 0) c_clock += n;

        }

        return min(c_clock_count, clock_count);
    }
};